using NUnit.Framework;

namespace OpenWaves.ImageTransformations.UnitTests
{
    [TestFixture]
    public class ScaleDownToFillTransformationTests
    {
        [Test]
        public void Transformation_does_not_transform__image_of_expected_size()
        {
            var imageMock = ImageMock.Create(50, 50);

            new ScaleDownToFillTransformation(50, 50).ApplyToImage(imageMock.Object);

            imageMock.VerifyAll();
        }

        [Test]
        public void Transformation_does_not_transform_smaller_image_of_expected_ratio()
        {
            var imageMock = ImageMock.Create(50, 50);

            new ScaleDownToFillTransformation(100, 100).ApplyToImage(imageMock.Object);

            imageMock.VerifyAll();
        }

        [Test]
        public void Transformation_crops_smaller_image_to_expected_aspect_ratio_1()
        {
            var imageMock = ImageMock.Create(50, 100);
            imageMock.Setup(i => i.Crop(0, 25, 50, 50)).Callback(() =>
                                                                     {
                                                                         imageMock.Setup(i => i.Width).Returns(50);
                                                                         imageMock.Setup(i => i.Height).Returns(50);
                                                                     });

            new ScaleDownToFillTransformation(200, 200).ApplyToImage(imageMock.Object);

            imageMock.VerifyAll();
        }

        [Test]
        public void Transformation_crops_smaller_image_to_expected_aspect_ratio_2()
        {
            var imageMock = ImageMock.Create(100, 50);
            imageMock.Setup(i => i.Crop(25, 0, 50, 50)).Callback(() =>
                                                                    {
                                                                        imageMock.Setup(i => i.Width).Returns(50);
                                                                        imageMock.Setup(i => i.Height).Returns(50);
                                                                    });

            new ScaleDownToFillTransformation(200, 200).ApplyToImage(imageMock.Object);

            imageMock.VerifyAll();
        }

        [Test]
        public void Transformation_scales_larger_image_to_fill_expected_rectangle_of_the_same_ratio()
        {
            var imageMock = ImageMock.Create(200, 500);
            imageMock.Setup(i => i.Scale(100, 250));

            new ScaleDownToFillTransformation(100, 250).ApplyToImage(imageMock.Object);

            imageMock.VerifyAll();
        }

        [Test]
        public void Transformation_scales_larger_image_to_fill_expected_rectangle_and_crops_to_expected_ratio()
        {
            var imageMock = ImageMock.Create(200, 500);
            imageMock.Setup(i => i.Crop(0, 150, 200, 200));
            imageMock.Setup(i => i.Scale(100, 100));

            new ScaleDownToFillTransformation(100, 100).ApplyToImage(imageMock.Object);

            imageMock.VerifyAll();
        }

    }
}